package org.github.manx98.jlibhac.fs.fsa;

import org.github.manx98.jlibhac.fs.IStorage;

import java.io.IOException;

/**
 * @author Manx98
 * @version 1.0
 * @since 2022/10/3 13:18
 */
public abstract class IFile extends IStorage {
    public IFile(long position) {
        super(position);
    }
    public long dryRead(long offset, int size, OpenMode openMode){

        // Check that we can read.
        if (!openMode.hasFlag(OpenMode.Read)){
            throw new IllegalStateException("Open mode not supported: " + openMode.toString());
        }

        // Get the file size, and validate our offset.
        long fileSize = getSize();

        if (offset > fileSize){
            throw new IllegalStateException("offset " + offset + " is out of file size range: " + fileSize);
        }

        return Math.min(fileSize - offset, size);
    }
    @Override
    public void close() throws IOException {
    }
}
